<!--这是添加产品分类组件-->
<template>
	<div style="padding-bottom: 30px;">
		<p class="filter"></p>
		<div class="addBox">
			<h3 class="fixTitle">
				<span>新增</span>
				<p>
					<em style="cursor: pointer;" @click="close"><svg-icon icon-class="cha" class="font-size16" /></em>
				</p>
			</h3>
      <el-form :model="tagData" :rules="rules" ref="postForm" label-width="140px" label-position="right" style="margin-top:40px;">
			<!-- <el-form class="form-container" style="font-size:14px;margin-top: 40px;"> -->
				<el-form-item label="名称：" prop="name">
					<el-input v-model="tagData.name" placeholder="请输入" style="width: 300px"></el-input>
				</el-form-item>
				<el-form-item label="顺序：">
					<el-input type="number" min="0" v-model="tagData.sort" placeholder="请输入" style="width: 300px"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-edit" @click="tagSave">保存</el-button>
					<el-button type="info" @click="close">关闭</el-button>
				</el-form-item>
			</el-form>
		</div>
	</div>
</template>
<script>
import { tagSave } from '@/api/goods'
  export default {
    props: ['tagData'],
    data() {
      return {
        rules: {
          name: [{required: true, message: '请输入名称', trigger: 'blur'}]
        }
      }
    },
    methods: {
      tagSave() {
        if (!this.tagData.name) {
					this.$message({
						type: 'error',
						message: '必须填写名称！'
					})
					return
				}
        if(this.tagData.sort < 0) {
          this.$message({
						type: 'error',
						message: '排序不能为负数'
					})
					return
        }
        var data = { data: { gtId: this.tagData.gtId, name: this.tagData.name, sort: this.tagData.sort } }
        tagSave(data).then(res => {
          this.$message({
            type: 'success',
            message: '操作成功'
          })
          this.close()
          this.$emit('saveTag')
        }).catch(err => {
          console.log(err)
        })
      },
      close() {
        this.$emit('hideAdd', false)
      }
    }
  }
</script>
<style scoped>
	p,h3 {margin:0;padding:0}
	.fixTitle{
		padding: 0 20px;
    width: 600px;
	}
	.addBox {
		width: 600px;
		height: 250px;
		background: #fff;
		position: fixed;
		left: 30%;
		top: 20%;
		z-index: 110;
	}
</style>
